package com.cande.loki.exercise.algorithm;

import java.util.*;

/**
 * @auther ROCK CODER
 * @DATE 2023/2/6 8:25
 * @Description 寻找链表的中间节点 快慢指针
 */
public class FindMidNode {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<ListNode> set = new ArrayList<>();
        String str = sc.nextLine();
        while (str != null && !str.equals("")) {
            String[] arr = str.split(" ");
            ListNode head = new ListNode();
            head.data = arr[0];
            set.add(head);
            str = sc.nextLine();
        }

        for (int i = 0; i<set.size();i++){
            if (set.size() >i+1) {
                set.get(i).next = set.get(i + 1);
            }
        }
        System.out.println(set);
        System.out.println(find(set.get(0)).data);

    }

    public static ListNode find(ListNode node){
        ListNode fast = node;
        ListNode slow = node;
        while(fast!=null && fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;

        }
        return slow;
    }

















}

